﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;

public static class MenuBuilder
{
  static List<string> hideTitle = new List<string>(new string[] { "Talas", "Zaloguj" });
  static string[] icons = new string[] { "home", "book", "envelope", "user" };
	public static string TopMenu()
	{
    int iconIndex = 0;
    StringBuilder sb = new StringBuilder();
    SiteMapNode currentNode = SiteMap.CurrentNode;
    SiteMapNode rootNode = SiteMap.RootNode;
    sb.Append("<div>");
    sb.Append("<div class=\"navbar\" id=\"NavigationMenu\" style=\"float: left\">");
    sb.Append("<ul class=\"level1 nav static\" tabindex=\"0\" role=\"menubar\">");
    foreach (SiteMapNode node in rootNode.ChildNodes)
    {
      bool s = (node.Url == currentNode.Url);
      if (node.HasChildNodes)
      {
        sb.Append("<li class=\"dropdown\" aria-haspopup=\"NavigationMenu:submenu:3\" role=\"menuitem\"><a class=\"dropdown-toggle" + (s ? " selected" : "") + "\" href=\"" + node.Url + "\" data-toggle=\"dropdown\">" + GetIcon(iconIndex++) + "<span>&nbsp;" + node.Title + "&nbsp;<b class=\"caret\"></b></span></a><ul class=\"level2 dropdown-menu dynamic\" id=\"NavigationMenu:submenu:3\">");
        foreach (SiteMapNode subnode in node.ChildNodes)
        {
          s = (subnode.Url == currentNode.Url);
          sb.Append("<li role=\"menuitem\" class=\"dynamic\"><a class=\"level2 dynamic"+(s?" selected":"")+"\" href=\"" + subnode.Url + "\">" + subnode.Title + "</a></li>");
        }
        sb.Append("</ul></li>");
      }
      else
      {
        sb.Append("<li role=\"menuitem\" class=\"static\"><a class=\"level1 static" + (s ? " selected" : "") + "\" href=\"" + node.Url + "\">" + GetIcon(iconIndex++) + (hideTitle.Contains(node.Title) ? "" : "<span>&nbsp;" + node.Title) + "</span></a></li>");
      }
    }
	  sb.Append("</ul>");
    sb.Append("</div><div style=\"clear: left;\"></div>");
    sb.Append("</div>");
    return sb.ToString();
	}
  private static string GetIcon(int index)
  {
    if (icons.Length > index && icons[index] != null && icons[index].Length > 0) 
      return "<i class=\"icon-" + icons[index] + "\"></i>";
    return "";
  }
}